package com.example.permissionservice.mapper;

import com.example.permissionservice.entity.UserRole;
import org.apache.ibatis.annotations.*;

import java.util.Optional;

@Mapper
public interface UserRoleMapper {
    @Select("SELECT * FROM user_roles WHERE user_id = #{userId}")
    Optional<UserRole> findByUserId(Long userId);

    @Insert("INSERT INTO user_roles(user_id, role_id) VALUES(#{userId}, #{roleId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(UserRole userRole);

    @Update("UPDATE user_roles SET role_id = #{roleId} WHERE id = #{id}")
    void update(UserRole userRole);
} 